{extend name="common/main"}

{block name="css"}
<!-- 本页面需要额外添加的css请在此处添加 -->
<style>
    #fileimg{
        display: block;
        width: 50px;
        height: 50px;
        /*-webkit-border-radius: 50%;*/
        /*-moz-border-radius: 50%;*/
        border-radius: 50%;
    }
</style>


{/block}

{block name="body"}
<body style="background: rgb(235, 236, 237);position:relative;">
<div class="tab_nav">
    <div class="header">
        <div class="h-left">
            <a class="sb-back" href="javascript:history.back(-1)" title="返回"></a>
        </div>
        <div class="h-mid">信息修改</div>
        <div class="h-right">
            <aside class="top_bar">
                <div onclick="show_menu();$('#close_btn').addClass('hid');" id="show_more"><a href="javascript:;"></a> </div>
            </aside>
        </div>
    </div>
    {include file="common/goods_nav"}
    <div id="tbh5v0">
        <div class="Personal">
            <div id="tbh5v0">
                <div class="innercontent1">
                    <form method="post"  id="edit_profile" >
                        <div class="name"><span>昵　 称</span>
                            <input type="text" name="nickname" id="nickname" value="{$user.nickname}" placeholder="*昵称"
                                   class="c-f-text">
                        </div>

                        <div class="name1"><span>性　 别</span>
                            <ul>
                                <li
                                <?php if($user['sex']==0) {echo 'class="on"';} ?>   >
                                <label for="sex0">
                                    <input type="radio" name="sex" value="0" tabindex="2" class="radio"
                                           id="sex0" <?php if($user['sex']==0) {echo 'checked="checked"';} ?>>
                                    保密</label>
                                </li>
                                <li
                                <?php if($user['sex']==1) {echo 'class="on"';} ?> >
                                <label for="sex1">
                                    <input type="radio" name="sex" value="1" tabindex="3" class="radio"
                                           id="sex1" <?php if($user['sex']==1) {echo 'checked="checked"';} ?> >
                                    男</label>
                                </li>
                                <li
                                <?php if($user['sex']==2) {echo 'class="on"';} ?> >
                                <label for="sex2">
                                    <input type="radio" name="sex" value="2" tabindex="4" class="radio"
                                           id="sex2" <?php if($user['sex']==2) {echo 'checked="checked"';} ?>>
                                    女</label>
                                </li>
                            </ul>
                        </div>
                        <div class="name">
                            <label for="email_ep"> <span>邮箱</span>
                                <input name="email" value="{$user.email}" id="email_ep" placeholder="*电子邮件地址" type="text"/>
                            </label>
                        </div>
                        <div class="name" style="height: 100px">
                            <label for="email_ep"> <span>推广二维码</span>
                                <img style="width: 100px" src="http://qr.liantu.com/api.php?text=http://lvyide.cn/mobilewx?leader={$user['mobile']}" alt="">
                            </label>
                        </div>

                        <div class="name">
                            <label for="email_ep"> <span>头像</span>
                                <a href="javascript:;" class="file" style="float: right"><div id="fileList" style="width:50px;height:50px;"><img src="{if $user.head_pic }{$user.head_pic}{else}/mobiled/images/user68.jpg{/if}" id="fileimg"></div><input style="width:50px;height:50px;" type="file" onChange="handleFiles(this,0)" name="image[]" accept="image/*"></a>
                                <!--<input type="file" name="image" /> <br>-->
                                <!--<input name="email" value="{$user.head_pic}" id="head_pic" placeholder="*电子邮件地址" type="text"/>-->
                            </label>
                        </div>
                        <div class="name"><span>会员信息</span>
                            {$Think.session.user['leve']['level_name']}(享受{$Think.session.user['leve']['discount']/100}折优惠)
                        </div>
                        <div class="field submit-btn">
                            <input type="hidden" name="code" value="name">
                            <input type="button" value="确认修改" onclick="setname('edit_profile')" class="btn_big1"/>
                        </div>
                    </form>
                </div>

                <!--<div class="innercontent1">-->
                    <!--<form method="post" action="" id="edit_mobile">-->
                        <!--<div class="name">-->
                            <!--<label for="email_ep"> <span>手机</span>-->
                                <!--<input name="mobile" value="{$user.mobile}" id="mobile_ep" placeholder="*手机号码" type="text"/>-->
                            <!--</label>-->
                        <!--</div>-->
                        <!--<div class="name">-->
                            <!--<label for="email_ep"> <span>验证码</span>-->
                                <!--<input type="text" id="mobile_code"  name="mobile_code" placeholder="手机验证码" />-->

                                <!--<input id="zphone" type="button" rel="mobile" value="获取手机验证码 " onClick="btnCheck()"-->
                                       <!--class="zphone">-->
                            <!--</label>-->
                        <!--</div>-->
                        <!--<div class="field submit-btn">-->
                            <!--<input type="hidden" name="code" value="mobile">-->

                            <!--<input type="button" value="确认修改" onclick="setname('edit_mobile')" class="btn_big1"/>-->
                        <!--</div>-->
                    <!--</form>-->
                <!--</div>-->

                <div class="innercontent11">
                    <form name="formPassword"  method="post" id="edit_pass" >
                        <h4 class="title">密码修改</h4>

                        <div class="field_pwd">
                            <label for="password">
                                <input type="password" name="old_password" id="password" class="c-f-text" placeholder="原密码"
                                       value=""/>
                            </label>
                        </div>
                        <div class="field_pwd">
                            <label for="new_password">
                                <input type="password" name="new_password" id="new_password" class="c-f-text"
                                       placeholder="新密码"/>
                            </label>
                        </div>
                        <div class="field_pwd">
                            <label for="comfirm_password">
                                <input type="password" name="confirm_password" id="comfirm_password" class="c-f-text"
                                       placeholder="确认密码"/>
                            </label>
                        </div>
                        <div class="field submit-btn">
                            <input type="hidden" name="code" value="pass">
                            <input type="button" value="确认修改" onclick="setname('edit_pass')" class="btn_big1"/>
                        </div>
                    </form>
                </div>
            </div>
        </div>

        <script>
            $('.name1 ul li').click(function () {
                $(this).find("input").attr("checked", "checked");
                $('.name1 ul li').removeClass("on");
                $(this).addClass("on");
            })
        </script>
    </div>

</div>


</body>
{/block}

{block name="js"}
<!-- 本页面需要额外添加的js请在此处添加 -->
<script src="/layer/layer.js"></script>
<script>
    /**
     * [btnCheck 按钮倒计时常用于获取手机短信验证码]
     */
    function btnCheck() {
        $mobile = $('[name="mobile"]').val();
        if ($mobile.length ==11){
            $.ajax({
                type : 'post',
                url : "{:url('User/vercod')}",
                data : {
                    'mobile':$mobile
                },
                success : function(res){
                    console.log(res);
                    if (res.code != 200) {
                        layer.msg(res.msg,{shade: 0.5, time: 2000, icon: 2});
                        return false;
                    }
                    layer.msg(res.msg, {shade: 0.5, time: 2000, icon: 1}, function(){
                        $(this).addClass("on");
                        var time = 60;
                        $(this).attr("disabled", true);
                        var timer = setInterval(function() {
                            if (time == 0) {
                                clearInterval(timer);
                                $("#zphone").attr("disabled", false);
                                $("#zphone").val("获取验证码");
                                $("#zphones").removeClass("on");
                            } else {
                                $('#zphone').val(time + "秒");
                                time--;
                            }
                        }, 1000);
                    });

                }
            })
        }else{
            layer.msg('请输入11位手机号',{shade: 0.5, time: 2000, icon: 2});
        }

    }

    function setname($id) {
        //提交
            var form=document.getElementById($id);

            var formData=new FormData(form);
            $.ajax({
                url:"{:Url('setname')}",
                type:'POST',
                data:formData,
                async: false,
                cache: false,
                contentType: false, //不设置内容类型
                processData: false, //不处理数据
                success:function(res){
                    if (res.code != 200) {
                        layer.msg(res.msg, {shade: 0.5, time: 2000,icon: 2});
                        return false;
                    }
                    layer.msg(res.msg, {shade: 0.5, time: 2000, icon: 1}, function(){
                        window.location.href=document.referrer;

                    });
                }
            });

    }
    $('.name1 ul li').click(function () {
        $(this).find("input").attr("checked", "checked");
        $('.name1 ul li').removeClass("on");
        $(this).addClass("on");
    })
    //头像
    window.URL = window.URL || window.webkitURL;
    function handleFiles(obj,id) {
        fileList = document.getElementById("fileList");
        console.log(fileList);
        var files = obj.files;
        img = new Image();
        if(window.URL){

            img.src = window.URL.createObjectURL(files[0]); //创建一个object URL，并不是你的本地路径
            img.id ="fileimg";
//            img.width = 50;
//            img.height = 50;
            img.onload = function(e) {
                window.URL.revokeObjectURL(this.src); //图片加载后，释放object URL
            }
            if(fileList.firstElementChild){
                fileList.removeChild(fileList.firstElementChild);
            }
            fileList.appendChild(img);
        }else if(window.FileReader){
            //opera不支持createObjectURL/revokeObjectURL方法。我们用FileReader对象来处理
            var reader = new FileReader();
            reader.readAsDataURL(files[0]);
            reader.onload = function(e){
                img.src = this.result;
                img.id ="fileimg";
//                img.width = 50;
//                img.height = 50;
                fileList.appendChild(img);
            }
        }else
        {
            //ie
            obj.select();
            obj.blur();
            var nfile = document.selection.createRange().text;
            document.selection.empty();
            img.src = nfile;
            img.id ="fileimg";
//            img.width = 50;
//            img.height = 50;
            img.onload=function(){

            }
            fileList.appendChild(img);
        }
    }
</script>


{/block}